import * as http from '@api/http'

/**
 * @purpose 创建订单
 * @param data
 * @returns {Promise<T>}
 */
export function create (data) {
  return http
    .post('order.create', data)
    .then(r => r.data)
}

/**
 * @purpose 获取微信支付凭证
 * @param orderNo
 * @returns {Promise<T>}
 */
export function payVoucher (orderNo, payMethod) {
  return http
    .get('order.payVoucher', {
      order_no: orderNo,
      pay_method: payMethod
    })
    .then(r => r.data)
}

/**
 * @purpose 微信支付同步回调查询
 * @param orderNo
 * @returns {Promise<T>}
 */
export function paySync (orderNo) {
  return http
    .get('order.paySync', {
      order_no: orderNo
    })
    .then(r => r.data)
}

/**
 * @purpose 获取不同状态的订单数量
 * @returns {PromiseLike<T> | Promise<T> | *}
 */
export function total () {
  return http
    .get('order.total')
    .then(r => r.data)
}

/**
 * @purpose 获取最新出行订单
 * @returns {PromiseLike<T> | Promise<T> | *}
 */
export function newOrderItems () {
  return http
    .get('order.newOrderItems')
    .then(r => r.data)
}

/**
 * @purpose 获取订单列表
 * @param status
 * @param page
 * @param size
 * @returns {PromiseLike<T> | Promise<T> | *}
 */
export function items (status = 1, page = 1, size = 20) {
  return http
    .get('order.items', {
      status: status,
      page: page,
      size: size
    })
    .then(r => r.data)
}

/**
 * @purpose 获取订单详情
 * @param orderNo
 * @returns {PromiseLike<T> | Promise<T> | *}
 */
export function detail (orderNo) {
  return http
    .get('order.detail', {
      order_no: orderNo
    })
    .then(r => r.data)
}

/**
 * @purpose 取消出行人
 * @param attachId
 * @returns {PromiseLike<T> | Promise<T> | *}
 */
export function cancelTravel (attachId) {
  return http
    .post('order.cancelTravel', {
      attach_id: attachId
    })
    .then(r => r.data)
}

/**
 * @purpose 取消订单(未支付时)
 * @param orderNo
 * @param reason
 * @returns {Promise<T>}
 */
export function cancelByNotPay (orderNo, reason) {
  return http
    .post('order.cancelByNotPay', {
      order_no: orderNo,
      reason: reason
    })
    .then(r => r.data)
}
/**
 * @purpose 申请取消订单
 * @param orderNo
 * @param reason
 * @returns {Promise<T>}
 */
export function cancelByPay (orderNo, reason) {
  return http
    .post('order.cancelByPay', {
      order_no: orderNo,
      reason: reason
    })
    .then(r => r.data)
}
/**
 * @purpose 取消单个出行人(未支付时)
 * @param attachId
 * @param reason
 * @returns {Promise<T>}
 */
export function cancelTravelByNotPay (attachId, reason) {
  return http
    .post('order.cancelTravelByNotPay', {
      attach_id: attachId,
      reason: reason
    })
    .then(r => r.data)
}

/**
 * @purpose 取消出行人(已支付)
 * @param attachId
 * @param reason
 * @returns {Promise<T>}
 */
export function cancelTravelByPay (attachId, reason) {
  return http
    .post('order.cancelTravelByPay', {
      attach_id: attachId,
      reason: reason
    })
    .then(r => r.data)
}
